package view.game
{
	//扑克牌资源
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	
	import util.*;
	
	public class CardBitmapData
	{
		public var cardBitmapData:Array; 				//扑克正面bitmapdata
		public var backBitmapData:BitmapData; 			//扑克背面bitmapdata
		public var cardWidth:Number = 0;				//扑克宽度
		public var cardHeight:Number = 0;				//扑克高度
			
		public function CardBitmapData(cardBitmap:Bitmap)
		{
			cardBitmap.smoothing = true;
			cardBitmapData = HeptaFishCovert.divide(cardBitmap, 13, 5);
			backBitmapData = cardBitmapData[54];
			cardWidth = backBitmapData.width;
			cardHeight = backBitmapData.height;
		}
		
		public function getBitmapData(data:uint):BitmapData
		{
			var color:uint = data & 0xF0;
			var value:uint = (data & 0x0F) - 1;
			var offset:uint;
			if(color == 0x0)
				offset = 2;
			else if(color == 0x10)
				offset = 3;
			else if(color == 0x20)
				offset = 1;
			else if(color == 0x30)
				offset = 0;
			else if(color == 0x40)
			{
				offset = 4;
				value = data==0x4F ? 1 : 0;
			}
			else
				throw new Error("错误的扑克数据！");
			
			return cardBitmapData[offset*13+value];
		}
		public function getMovieClip(data:uint, bright:Boolean=true):MovieClip
		{
			if(bright)
				return Graphics.createMcByBitmapData(getBitmapData(data));
			else
				return Graphics.createMcByBitmapData(backBitmapData);
		}
	}
}